import { getParentOrg } from './service';
import { selectPersonTreeList, getAsynKeyUser, getGroupList } from './service';
import { FormSchema } from '/@/components/Form';
import { selectSuperDepartTreeList } from '/@/api/common/api';
export const detailForm: FormSchema[] = [
  {
    label: '考核单位编码',
    field: 'orgCode',
    component: 'Input',
    dynamicDisabled: () => {
      return true;
    },
    colProps: { span: 8 },
  },
  {
    label: '考核单位简称',
    field: 'suitUnitName',
    component: 'Input',
    dynamicDisabled: () => {
      return true;
    },
    colProps: { span: 8 },
  },
  {
    label: '上级考核单位',
    field: 'parentName',
    component: 'Input',
    dynamicDisabled: () => {
      return true;
    },
    colProps: { span: 8 },
  },
  {
    label: '绩效管理员',
    field: 'managerName',
    component: 'Input',
    dynamicDisabled: () => {
      return true;
    },
    colProps: { span: 8 },
  },
  {
    field: 'unitType',
    label: '单位分类',
    component: 'ZDictSelectTag',
    componentProps: {
      dictCode: 'hub_suit_type',
      placeholder: '请选择分类',
      disabled: true,
    },
    colProps: { span: 8 },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
    dynamicDisabled: () => {
      return true;
    },
    colProps: { span: 8 },
  },
];

export const editForm: FormSchema[] = [
  {
    label: 'id',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'flag',
    label: 'flag值',
    component: 'Input',
    show: false,
  },
  {
    field: 'suitUnitName',
    label: '考核单位简称',
    component: 'Input',
    required: true,
  },
  // {
  //   field: 'orgCode',
  //   label: '考核单位编码',
  //   component: 'Input',
  //   dynamicDisabled: ({ values }) => {
  //     return !!values.id;
  //   },
  //   required: true,
  // },
  {
    field: 'unitType',
    label: '考核单位分类',
    component: 'ZDictSelectTag',
    componentProps: {
      dictCode: 'hub_suit_type',
      placeholder: '请选择分类',
    },
    required: true,
  },
  {
    field: 'stTypeCode',
    label: '考核单位分组',
    component: 'ApiSelect',
    // dynamicRules: () => {
    //   return [
    //     {
    //       required: true,
    //       validator: (_, value) => {
    //         if (undefined !== typeof value) {
    //           return Promise.resolve();
    //         } else {
    //           return Promise.reject('错误验证');
    //         }
    //       },
    //     },
    //   ];
    // },
    componentProps: {
      api: getGroupList,
      labelField: 'stTypeName',
      valueField: 'stTypeCode',
      getPopupContainer: () => document.body,
    },
  },
  // {
  //   field: 'stTypeCode',
  //   label: '考核单位分组',
  //   component: 'Input',
  //   required: true,
  // },
  // {
  //   field: 'orgCode',
  //   label: '所属部门编码',
  //   component: 'Input',
  //   show: false,
  // },
  {
    field: 'orgName',
    label: '绩效关联部门',
    component: 'Input',
    // componentProps: ({ formModel }) => {
    //   return {
    //     api: getAsynDeptTree,
    //     parentCode: {
    //       key: 'id',
    //       parentKey: 'parentId',
    //     },
    //     fieldNames: {
    //       children: 'children',
    //       label: 'deptName',
    //       value: 'deptCode',
    //     },
    //     // @ts-ignore
    //     onSelect: (v, node) => {
    //       formModel.orgCode = node.id;
    //     },
    //     getPopupContainer: () => document.body,
    //   };
    // },
    required: true,
  },
  {
    field: 'orgCode',
    label: '绩效关联部门编码',
    component: 'Input',
    show: false,
  },
  {
    field: 'managerName',
    label: '绩效管理员',
    component: 'Input',
    show: false,
  },
  {
    field: 'managerCode',
    label: '绩效管理员编码',
    component: 'Input',
    show: false,
  },
  // {
  //   field: 'managerName',
  //   label: '绩效管理员',
  //   component: 'ApiTreeSelect',
  //   componentProps: ({ formModel }) => {
  //     return {
  //       api: getAsynKeyUser,
  //       parentCode: {
  //         key: 'id',
  //         parentKey: 'parentId',
  //       },
  //       fieldNames: {
  //         children: 'children',
  //         label: 'name',
  //         value: 'name',
  //       },
  //       // @ts-ignore
  //       onSelect: (v, node) => {
  //         formModel.manager = node.code;
  //       },
  //     };
  //   },
  //   required: true,
  // },
  {
    label: '绩效管理员',
    field: 'manager',
    required: false,
    component: 'ZSelectCustom',
    componentProps: ({ formModel }) => {
      console.log('formModel', formModel);
      return {
        sync: true,
        queryApi: selectPersonTreeList,
        titleKey: 'title',
        rowKey: 'psnNum',
        multiple: false, //多选
        modalTitle: '人员选择',
        showSearch: true,
        maxTagCount: 3,
        // options: [{ label: formModel.managerName ? formModel.managerName : '', value: formModel.manager ? formModel.manager[0] : '' }],
        params: {
          type: '1',
        },
      };
    },
  },
  // {
  //   field: 'parentCode',
  //   label: '上级单位',
  //   component: 'ApiTreeSelect',
  //   componentProps: {
  //     api: getParentOrg,
  //     fieldNames: {
  //       children: 'childBaseSuitunitUp',
  //       label: 'suitUnitName',
  //       value: 'suitUnitCode',
  //     },
  //     getPopupContainer: () => document.body,
  //   },
  // },
  // {
  //   field: 'displayOrder',
  //   label: '排序',
  //   component: 'InputNumber',
  // },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    componentProps: {
      rows: 5,
    },
    dynamicRules: () => {
      return [
        {
          validator: (_, value) => {
            if (null != value && value.length && value.length > 500) {
              return Promise.reject('备注字数不能超过500');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
];
